package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResultVo;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/4 23:40
 */
@RestController
@RequestMapping("/messages")
public class MessageController {


    @Autowired
    private MessageService messageService;

    /**
     * 根据环信ID查询用户详细信息
     */
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId) {
        UserInfoVo vo = messageService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }


    /**
     * 添加好友
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){

        // 获取好友id
        String id = map.get("userId").toString();
        Long friendId = Long.valueOf(id);
        // 调用service添加好友
        messageService.contacts(friendId);
        return ResponseEntity.ok(null);
    }


    /**
     * 分页查询联系人列表
     * @param page
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                   String keyword){

       PageResultVo vo =  messageService.findFriends(page, pageSize, keyword);
        return ResponseEntity.ok(vo);
    }


}
